const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
  phoneNumber: {
    type: String,
    required: true,
    unique: true,
    trim: true
  },
  isRegistered: {
    type: Boolean,
    default: false
  },
  registrationTime: {
    type: Date,
    default: Date.now
  },
  lastLoginTime: {
    type: Date,
    default: Date.now
  },
  loginCount: {
    type: Number,
    default: 0
  },
  status: {
    type: String,
    enum: ['active', 'inactive', 'blocked'],
    default: 'active'
  },
  // 微信登录相关字段
  wechatOpenId: { type: String, unique: true, sparse: true },
  wechatUnionId: { type: String, unique: true, sparse: true },
  wechatNickname: { type: String },
  wechatAvatar: { type: String },
  wechatAccessToken: { type: String },
  wechatRefreshToken: { type: String },
  wechatTokenExpiresAt: { type: Date },
  loginType: { type: String, enum: ['phone', 'wechat', 'qq', 'apple', 'face'], default: 'phone' },
  // 人脸识别相关字段
  faceFeatures: { type: String }, // 人脸特征数据
  faceImageUrl: { type: String } // 人脸图像URL
}, {
  timestamps: true
});

// 创建索引以提高查询性能
userSchema.index({ phoneNumber: 1 });

module.exports = mongoose.model('User', userSchema); 